package impl

import (
	"adam2/internal/vo"
	pConstants "anubis-framework/pkg/constants"
	pDomain "anubis-framework/pkg/domain"
	"anubis-framework/pkg/util"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

type RelStockInfoConceptBoardControllerImpl struct {
	*BaseControllerImpl
}

// 获取RelStockInfoConceptBoardControllerImpl
func GetRelStockInfoConceptBoardControllerImpl() *RelStockInfoConceptBoardControllerImpl {
	return &RelStockInfoConceptBoardControllerImpl{GetBaseControllerImpl()}
}

// 分页显示
func (_relStockInfoConceptBoardControllerImpl *RelStockInfoConceptBoardControllerImpl) Page(c *gin.Context) {
	// 转换参数
	var pageRelStockInfoConceptBoardVo *vo.PageRelStockInfoConceptBoardVo = &vo.PageRelStockInfoConceptBoardVo{}
	c.BindJSON(pageRelStockInfoConceptBoardVo)

	// 参数验证：参数pageNo和pageSize不能为空
	if pageRelStockInfoConceptBoardVo.PageNo == 0 || pageRelStockInfoConceptBoardVo.PageSize == 0 {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数pageNo和pageSize不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 参数验证：参数transactionDate不能为空
	if pageRelStockInfoConceptBoardVo.TransactionDate == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数transactionDate不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 参数验证：参数conceptBoardName不能为空
	if pageRelStockInfoConceptBoardVo.ConceptBoardName == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数conceptBoardName不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 分页
	var transactionDate time.Time = util.StringToDate(pageRelStockInfoConceptBoardVo.TransactionDate)
	var serviceResult *pDomain.ServiceResult = _relStockInfoConceptBoardControllerImpl._relStockInfoConceptBoardServiceImpl.Page(pageRelStockInfoConceptBoardVo.OrderByColumnArray, pageRelStockInfoConceptBoardVo.ConceptBoardName, transactionDate, pageRelStockInfoConceptBoardVo.PageNo, pageRelStockInfoConceptBoardVo.PageSize)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}
